package uml.eventsystem;

import java.util.HashMap;

import javax.swing.KeyStroke;

import uml.eventsystem.events.UMLEventId;

public class KeyMap 
{
	private static HashMap<KeyStroke, UMLEventId> m_keyShortcuts;
	private static void initKeyMap() 
	{
		m_keyShortcuts = new HashMap<KeyStroke, UMLEventId>();
		
		/*
		*Instructions to add key shortcuts
		*the addShortcut method takes in a string and a UMLEventId
		*
		*the string is defined as following:
		*string -> <modifiers>* (<typedID> | <pressedReleasedID>)
		*modifiers -> shift | control | ctrl | meta | alt | altGraph
		*typedID -> typed <typedKey>
		*typedKey -> [:Unicode Character:]
		*pressedReleasedID -> (pressed | released) key
		*key -> [:Keyevent key code:]
		*
		*Some english comments
		*A key is the same as the text in the KeyEvent keycodes after "VK_"
		*The main format you will use is "modifiers* key"
		*/
		addShortcut("control Q", UMLEventId.APPLICATION_EXIT);
		addShortcut("control N", UMLEventId.CREATE_DIAGRAM);
		addShortcut("alt N", UMLEventId.MAKE_NOTE);
		addShortcut("alt C", UMLEventId.MAKE_CLASS);
		addShortcut("alt P", UMLEventId.MAKE_PACKAGE);
		addShortcut("alt I", UMLEventId.MAKE_INTERFACE);
		addShortcut("control D", UMLEventId.DELETE);
	}
	
	/**
	 * private constructor
	 */
	private KeyMap()
	{
		
	}
	
	/**
	 * returns m_keyShortcuts if they are not null.
	 * @return
	 */
	public static HashMap<KeyStroke, UMLEventId> getKeyMap()
	{
		if(m_keyShortcuts == null)
			initKeyMap();
		return m_keyShortcuts;
	}
	
	/**
	 * adds shortcuts
	 * @param keyShortcut
	 * @param event
	 */
	private static void addShortcut(String keyShortcut, UMLEventId event)
	{
		KeyStroke keyStroke = KeyStroke.getKeyStroke(keyShortcut);
		m_keyShortcuts.put(keyStroke, event);
	}
	
}
